package cn.elead.it.sso.system.sql;

import org.apache.ibatis.jdbc.SQL;

import com.gitee.elead.api.ApiUtils;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;

public class PermissionSql {

	/**
	 * 查询简单权限SQL
	 * 
	 * @param eSsoPermission 简单权限
	 * @return sql
	 */
	public String findById(String id) {
		return new SQL() {
			{
				SELECT("E.ID, E.STATUS, E.ORDERBY, E.REVISION, E.DELETED, E.CREATED_BY, E.CREATED_TIME, E.UPDATED_BY, E.UPDATED_TIME ");
				FROM("E_SSO_PERMISSION E");
				if (ObjectUtil.isNotEmpty(id)) {
					WHERE("E.ID = #{id}");
				}
				ORDER_BY("CREATED_TIME DESC");
			}
		}.toString();
	}

	/**
	 * 更新简单权限删除标志SQL
	 * 
	 * @param id
	 * @return sql
	 */
	public String updateDelById(String id) {
		return new SQL() {
			{
				UPDATE("E_SSO_PERMISSION");
				SET("DELETED = 0");
				SET("UPDATED_BY = '" + ApiUtils.currentUid() + "'");
				SET("UPDATED_TIME = '" + DateUtil.now() + "'");
				if (ObjectUtil.isNotEmpty(id)) {
					WHERE("ID = #{id}");
				}
			}
		}.toString();
	}
}
